{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from requests_html import HTMLSession"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>edu</th>\n",
       "      <th>经验</th>\n",
       "      <th>薪水</th>\n",
       "      <th>时间</th>\n",
       "      <th>职称</th>\n",
       "      <th>公司地点</th>\n",
       "      <th>公司名称</th>\n",
       "      <th>链结</th>\n",
       "      <th>公司URL</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>13-16k·12薪</td>\n",
       "      <td>2020年07月02日</td>\n",
       "      <td>内容运营经理（短视频）</td>\n",
       "      <td>广州-天河区</td>\n",
       "      <td>中食安泓(广东)健康产业有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929588665.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10182163/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>4-6k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>石家庄-裕华区</td>\n",
       "      <td>河北小丽生物科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929716219.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10005065/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>统招本科</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>18-23k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频赛道运营</td>\n",
       "      <td></td>\n",
       "      <td>中软国际科技</td>\n",
       "      <td>https://www.liepin.com/job/1929714691.shtml</td>\n",
       "      <td>https://www.liepin.com/company/7927849/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>26-35k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营总监</td>\n",
       "      <td>杭州</td>\n",
       "      <td>杭州宸帆电子商务有限责任公司</td>\n",
       "      <td>https://www.liepin.com/job/1929714349.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9193968/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>6-8k·13薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>广州-越秀区</td>\n",
       "      <td>屈臣氏</td>\n",
       "      <td>https://www.liepin.com/job/1929713899.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8278552/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>一年以下</td>\n",
       "      <td>8-12k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td></td>\n",
       "      <td>北京多彩投网络科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929713691.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8922105/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>8-15k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>深圳-南山区</td>\n",
       "      <td>深圳小坏科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929708339.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12002445/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>学历不限</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频内容运营</td>\n",
       "      <td>北京</td>\n",
       "      <td>小米</td>\n",
       "      <td>https://www.liepin.com/job/1929705583.shtml</td>\n",
       "      <td>https://www.liepin.com/company/2174886/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>4-6k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频电商运营</td>\n",
       "      <td>深圳-龙华区</td>\n",
       "      <td>深圳市吉羊互娱传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929704031.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12140009/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>6-10k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频全平台运营</td>\n",
       "      <td>广州-西关</td>\n",
       "      <td>广州市悍森服饰有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929703703.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12300683/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>5-8k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>上海</td>\n",
       "      <td>上海弘冠化妆品有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929702711.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12240191/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>学历不限</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>8-15k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营负责人</td>\n",
       "      <td>徐州</td>\n",
       "      <td>徐州宏格金智文化传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929698021.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12301545/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-25k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频创意策划/运营</td>\n",
       "      <td>北京</td>\n",
       "      <td>聚美</td>\n",
       "      <td>https://www.liepin.com/job/1929698001.shtml</td>\n",
       "      <td>https://www.liepin.com/company/7865938/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>学历不限</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>4-8k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>郑州-金水区</td>\n",
       "      <td>河南屯和文化传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929697545.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12299553/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>10年以上</td>\n",
       "      <td>40-60k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营负责人</td>\n",
       "      <td>上海-江湾</td>\n",
       "      <td>上海炫石文化传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929694783.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9382425/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>8-12k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td></td>\n",
       "      <td>雍禾医疗</td>\n",
       "      <td>https://www.liepin.com/job/1929693995.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8959901/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>一年以下</td>\n",
       "      <td>8-14k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营专员 (MJ000415)</td>\n",
       "      <td></td>\n",
       "      <td>朴新网校</td>\n",
       "      <td>https://www.liepin.com/job/1929693525.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9710083/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>8-10k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>武汉-徐东</td>\n",
       "      <td>武汉森巴迪商贸有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929692977.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9279956/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>中专/中技及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>4-6k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>汕尾</td>\n",
       "      <td>海丰县黛美妆贸易有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929691645.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12285185/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>学历不限</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>4-5k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营助理</td>\n",
       "      <td></td>\n",
       "      <td>上海维迈文化传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929661241.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10233487/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>8-15k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td></td>\n",
       "      <td>北京视游互动科技</td>\n",
       "      <td>https://www.liepin.com/job/1929632627.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8719549/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>5-8k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营编剧</td>\n",
       "      <td>广州-从化区</td>\n",
       "      <td>广州浩恩奉仕食品有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929627409.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8515896/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>8-10k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频/直播运营（J12034）</td>\n",
       "      <td>深圳-南山区</td>\n",
       "      <td>潮漫酒店管理(深圳)有限公司广州分公司</td>\n",
       "      <td>https://www.liepin.com/job/1929622663.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12154341/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>统招本科</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>5-10k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营助理 (MJ000221)</td>\n",
       "      <td>杭州-拱墅区</td>\n",
       "      <td>杭州米络星科技(集团)有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929618131.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8022133/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>3-5k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>江门-鹤山</td>\n",
       "      <td>法罗力</td>\n",
       "      <td>https://www.liepin.com/job/1929610847.shtml</td>\n",
       "      <td>https://www.liepin.com/company/7992866/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>统招本科</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>7-10k·13薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>杭州-西湖区</td>\n",
       "      <td>浙江艾罗网络能源技术有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929597995.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8848987/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>7-14k·14薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>广州</td>\n",
       "      <td>广州万物有翼科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929593729.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10083619/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>4-9k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>武汉</td>\n",
       "      <td>武汉放逐文化传媒有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929555531.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12282851/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>10-20k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营负责人/内容变现总监</td>\n",
       "      <td>郑州-郑东新区</td>\n",
       "      <td>郑州一代宗师中医馆有限公司郑东门诊部</td>\n",
       "      <td>https://www.liepin.com/job/1929537071.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9730683/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>8-10k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>长沙</td>\n",
       "      <td>湖南汇富康达健康科技集团有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929529939.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9891561/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-25k·13薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>上海-浦东新区</td>\n",
       "      <td>上海元靖信息科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929522771.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12152071/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>8-15k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>广州-市桥</td>\n",
       "      <td>广州倍新健身服务有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929520401.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9785861/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>成都</td>\n",
       "      <td>北京三合鸿业科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929500967.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10207805/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>武汉-洪山区</td>\n",
       "      <td>北京三合鸿业科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929500959.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10207805/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>杭州-上城区</td>\n",
       "      <td>北京三合鸿业科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929500957.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10207805/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>上海-黄浦区</td>\n",
       "      <td>北京三合鸿业科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929500951.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10207805/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>3-5年</td>\n",
       "      <td>15-30k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>大连-中山区</td>\n",
       "      <td>北京三合鸿业科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929500949.shtml</td>\n",
       "      <td>https://www.liepin.com/company/10207805/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>经验不限</td>\n",
       "      <td>8-11k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>西安</td>\n",
       "      <td>西安信得天下数据服务有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929450851.shtml</td>\n",
       "      <td>https://www.liepin.com/company/12145515/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>大专及以上</td>\n",
       "      <td>5-10年</td>\n",
       "      <td>10-20k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营经理</td>\n",
       "      <td>上海-徐汇区</td>\n",
       "      <td>上海晓筑教育科技有限公司</td>\n",
       "      <td>https://www.liepin.com/job/1929430353.shtml</td>\n",
       "      <td>https://www.liepin.com/company/9161191/</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>本科及以上</td>\n",
       "      <td>1-3年</td>\n",
       "      <td>7-13k·12薪</td>\n",
       "      <td>2020年07月07日</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>常州-新北区</td>\n",
       "      <td>赛格威-纳恩博</td>\n",
       "      <td>https://www.liepin.com/job/1929367337.shtml</td>\n",
       "      <td>https://www.liepin.com/company/8628501/</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         edu     经验          薪水           时间                  职称     公司地点  \\\n",
       "0      大专及以上   3-5年  13-16k·12薪  2020年07月02日         内容运营经理（短视频）   广州-天河区   \n",
       "1      大专及以上   经验不限    4-6k·12薪  2020年07月07日               短视频运营  石家庄-裕华区   \n",
       "2       统招本科   经验不限  18-23k·12薪  2020年07月07日             短视频赛道运营            \n",
       "3      本科及以上   3-5年  26-35k·12薪  2020年07月07日             短视频运营总监       杭州   \n",
       "4      大专及以上   3-5年    6-8k·13薪  2020年07月07日               短视频运营   广州-越秀区   \n",
       "5      本科及以上   一年以下   8-12k·12薪  2020年07月07日               短视频运营            \n",
       "6      大专及以上   经验不限   8-15k·12薪  2020年07月07日               短视频运营   深圳-南山区   \n",
       "7       学历不限   3-5年  15-30k·12薪  2020年07月07日             短视频内容运营       北京   \n",
       "8      大专及以上   经验不限    4-6k·12薪  2020年07月07日             短视频电商运营   深圳-龙华区   \n",
       "9      大专及以上   1-3年   6-10k·12薪  2020年07月07日            短视频全平台运营    广州-西关   \n",
       "10     大专及以上   1-3年    5-8k·12薪  2020年07月07日               短视频运营       上海   \n",
       "11      学历不限   1-3年   8-15k·12薪  2020年07月07日            短视频运营负责人       徐州   \n",
       "12     本科及以上   3-5年  15-25k·12薪  2020年07月07日          短视频创意策划/运营       北京   \n",
       "13      学历不限   1-3年    4-8k·12薪  2020年07月07日               短视频运营   郑州-金水区   \n",
       "14     本科及以上  10年以上  40-60k·12薪  2020年07月07日            短视频运营负责人    上海-江湾   \n",
       "15     大专及以上   3-5年   8-12k·12薪  2020年07月07日               短视频运营            \n",
       "16     本科及以上   一年以下   8-14k·12薪  2020年07月07日  短视频运营专员 (MJ000415)            \n",
       "17     大专及以上   3-5年   8-10k·12薪  2020年07月07日               短视频运营    武汉-徐东   \n",
       "18  中专/中技及以上   经验不限    4-6k·12薪  2020年07月07日               短视频运营       汕尾   \n",
       "19      学历不限   经验不限    4-5k·12薪  2020年07月07日             短视频运营助理            \n",
       "20     本科及以上   1-3年   8-15k·12薪  2020年07月07日               短视频运营            \n",
       "21     大专及以上   1-3年    5-8k·12薪  2020年07月07日             短视频运营编剧   广州-从化区   \n",
       "22     大专及以上   1-3年   8-10k·12薪  2020年07月07日    短视频/直播运营（J12034）   深圳-南山区   \n",
       "23      统招本科   经验不限   5-10k·12薪  2020年07月07日  短视频运营助理 (MJ000221)   杭州-拱墅区   \n",
       "24     大专及以上   1-3年    3-5k·12薪  2020年07月07日               短视频运营    江门-鹤山   \n",
       "25      统招本科   1-3年   7-10k·13薪  2020年07月07日               短视频运营   杭州-西湖区   \n",
       "26     本科及以上   1-3年   7-14k·14薪  2020年07月07日               短视频运营       广州   \n",
       "27     本科及以上   经验不限    4-9k·12薪  2020年07月07日               短视频运营       武汉   \n",
       "28     大专及以上   3-5年  10-20k·12薪  2020年07月07日     短视频运营负责人/内容变现总监  郑州-郑东新区   \n",
       "29     本科及以上   1-3年   8-10k·12薪  2020年07月07日               短视频运营       长沙   \n",
       "30     本科及以上   3-5年  15-25k·13薪  2020年07月07日               短视频运营  上海-浦东新区   \n",
       "31     大专及以上   1-3年   8-15k·12薪  2020年07月07日               短视频运营    广州-市桥   \n",
       "32     大专及以上   3-5年  15-30k·12薪  2020年07月07日               短视频运营       成都   \n",
       "33     大专及以上   3-5年  15-30k·12薪  2020年07月07日               短视频运营   武汉-洪山区   \n",
       "34     大专及以上   3-5年  15-30k·12薪  2020年07月07日               短视频运营   杭州-上城区   \n",
       "35     大专及以上   3-5年  15-30k·12薪  2020年07月07日               短视频运营   上海-黄浦区   \n",
       "36     大专及以上   3-5年  15-30k·12薪  2020年07月07日               短视频运营   大连-中山区   \n",
       "37     本科及以上   经验不限   8-11k·12薪  2020年07月07日               短视频运营       西安   \n",
       "38     大专及以上  5-10年  10-20k·12薪  2020年07月07日             短视频运营经理   上海-徐汇区   \n",
       "39     本科及以上   1-3年   7-13k·12薪  2020年07月07日               短视频运营   常州-新北区   \n",
       "\n",
       "                   公司名称                                           链结  \\\n",
       "0      中食安泓(广东)健康产业有限公司  https://www.liepin.com/job/1929588665.shtml   \n",
       "1          河北小丽生物科技有限公司  https://www.liepin.com/job/1929716219.shtml   \n",
       "2                中软国际科技  https://www.liepin.com/job/1929714691.shtml   \n",
       "3        杭州宸帆电子商务有限责任公司  https://www.liepin.com/job/1929714349.shtml   \n",
       "4                   屈臣氏  https://www.liepin.com/job/1929713899.shtml   \n",
       "5         北京多彩投网络科技有限公司  https://www.liepin.com/job/1929713691.shtml   \n",
       "6            深圳小坏科技有限公司  https://www.liepin.com/job/1929708339.shtml   \n",
       "7                    小米  https://www.liepin.com/job/1929705583.shtml   \n",
       "8         深圳市吉羊互娱传媒有限公司  https://www.liepin.com/job/1929704031.shtml   \n",
       "9           广州市悍森服饰有限公司  https://www.liepin.com/job/1929703703.shtml   \n",
       "10          上海弘冠化妆品有限公司  https://www.liepin.com/job/1929702711.shtml   \n",
       "11       徐州宏格金智文化传媒有限公司  https://www.liepin.com/job/1929698021.shtml   \n",
       "12                   聚美  https://www.liepin.com/job/1929698001.shtml   \n",
       "13         河南屯和文化传媒有限公司  https://www.liepin.com/job/1929697545.shtml   \n",
       "14         上海炫石文化传媒有限公司  https://www.liepin.com/job/1929694783.shtml   \n",
       "15                 雍禾医疗  https://www.liepin.com/job/1929693995.shtml   \n",
       "16                 朴新网校  https://www.liepin.com/job/1929693525.shtml   \n",
       "17          武汉森巴迪商贸有限公司  https://www.liepin.com/job/1929692977.shtml   \n",
       "18         海丰县黛美妆贸易有限公司  https://www.liepin.com/job/1929691645.shtml   \n",
       "19         上海维迈文化传媒有限公司  https://www.liepin.com/job/1929661241.shtml   \n",
       "20             北京视游互动科技  https://www.liepin.com/job/1929632627.shtml   \n",
       "21         广州浩恩奉仕食品有限公司  https://www.liepin.com/job/1929627409.shtml   \n",
       "22  潮漫酒店管理(深圳)有限公司广州分公司  https://www.liepin.com/job/1929622663.shtml   \n",
       "23      杭州米络星科技(集团)有限公司  https://www.liepin.com/job/1929618131.shtml   \n",
       "24                  法罗力  https://www.liepin.com/job/1929610847.shtml   \n",
       "25       浙江艾罗网络能源技术有限公司  https://www.liepin.com/job/1929597995.shtml   \n",
       "26         广州万物有翼科技有限公司  https://www.liepin.com/job/1929593729.shtml   \n",
       "27         武汉放逐文化传媒有限公司  https://www.liepin.com/job/1929555531.shtml   \n",
       "28   郑州一代宗师中医馆有限公司郑东门诊部  https://www.liepin.com/job/1929537071.shtml   \n",
       "29     湖南汇富康达健康科技集团有限公司  https://www.liepin.com/job/1929529939.shtml   \n",
       "30         上海元靖信息科技有限公司  https://www.liepin.com/job/1929522771.shtml   \n",
       "31         广州倍新健身服务有限公司  https://www.liepin.com/job/1929520401.shtml   \n",
       "32         北京三合鸿业科技有限公司  https://www.liepin.com/job/1929500967.shtml   \n",
       "33         北京三合鸿业科技有限公司  https://www.liepin.com/job/1929500959.shtml   \n",
       "34         北京三合鸿业科技有限公司  https://www.liepin.com/job/1929500957.shtml   \n",
       "35         北京三合鸿业科技有限公司  https://www.liepin.com/job/1929500951.shtml   \n",
       "36         北京三合鸿业科技有限公司  https://www.liepin.com/job/1929500949.shtml   \n",
       "37       西安信得天下数据服务有限公司  https://www.liepin.com/job/1929450851.shtml   \n",
       "38         上海晓筑教育科技有限公司  https://www.liepin.com/job/1929430353.shtml   \n",
       "39              赛格威-纳恩博  https://www.liepin.com/job/1929367337.shtml   \n",
       "\n",
       "                                       公司URL  \n",
       "0   https://www.liepin.com/company/10182163/  \n",
       "1   https://www.liepin.com/company/10005065/  \n",
       "2    https://www.liepin.com/company/7927849/  \n",
       "3    https://www.liepin.com/company/9193968/  \n",
       "4    https://www.liepin.com/company/8278552/  \n",
       "5    https://www.liepin.com/company/8922105/  \n",
       "6   https://www.liepin.com/company/12002445/  \n",
       "7    https://www.liepin.com/company/2174886/  \n",
       "8   https://www.liepin.com/company/12140009/  \n",
       "9   https://www.liepin.com/company/12300683/  \n",
       "10  https://www.liepin.com/company/12240191/  \n",
       "11  https://www.liepin.com/company/12301545/  \n",
       "12   https://www.liepin.com/company/7865938/  \n",
       "13  https://www.liepin.com/company/12299553/  \n",
       "14   https://www.liepin.com/company/9382425/  \n",
       "15   https://www.liepin.com/company/8959901/  \n",
       "16   https://www.liepin.com/company/9710083/  \n",
       "17   https://www.liepin.com/company/9279956/  \n",
       "18  https://www.liepin.com/company/12285185/  \n",
       "19  https://www.liepin.com/company/10233487/  \n",
       "20   https://www.liepin.com/company/8719549/  \n",
       "21   https://www.liepin.com/company/8515896/  \n",
       "22  https://www.liepin.com/company/12154341/  \n",
       "23   https://www.liepin.com/company/8022133/  \n",
       "24   https://www.liepin.com/company/7992866/  \n",
       "25   https://www.liepin.com/company/8848987/  \n",
       "26  https://www.liepin.com/company/10083619/  \n",
       "27  https://www.liepin.com/company/12282851/  \n",
       "28   https://www.liepin.com/company/9730683/  \n",
       "29   https://www.liepin.com/company/9891561/  \n",
       "30  https://www.liepin.com/company/12152071/  \n",
       "31   https://www.liepin.com/company/9785861/  \n",
       "32  https://www.liepin.com/company/10207805/  \n",
       "33  https://www.liepin.com/company/10207805/  \n",
       "34  https://www.liepin.com/company/10207805/  \n",
       "35  https://www.liepin.com/company/10207805/  \n",
       "36  https://www.liepin.com/company/10207805/  \n",
       "37  https://www.liepin.com/company/12145515/  \n",
       "38   https://www.liepin.com/company/9161191/  \n",
       "39   https://www.liepin.com/company/8628501/  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-1   单一页面\n",
    "url = \"https://www.liepin.com/zhaopin/?key=短视频运营\"\n",
    "session = HTMLSession()\n",
    "r = session.get( url )\n",
    "\n",
    "# 先取特定元素, 精准打击其子后辈\n",
    "主要元素 = r.html.xpath( \\\n",
    "    '//ul[@class=\"sojob-list\"]/li')\n",
    "\n",
    "# 预期是一个元素的列表？\n",
    "#print (主要元素[0].xpath('//div[contains(@class,\"sojob-item-main\")]'))\n",
    "#print (主要元素[0].xpath('//div[contains(@class,\"job-info\")]/h3/a'))\n",
    "#print (主要元素[3].xpath('//div[contains(@class,\"job-info\")]/p/a'))\n",
    "#print (主要元素[3].xpath('//div[contains(@class,\"job-info\")]/p/span[@class=\"text-warning\"]'))\n",
    "#print (主要元素[3].xpath('//div[contains(@class,\"job-info\")]/p/span[@class=\"edu\"]/following-sibling::span'))\n",
    "#print (主要元素[3].xpath('//div[contains(@class,\"job-info\")]/p/time/@title'))\n",
    "#print (主要元素[0].xpath('//div[contains(@class,\"sojob-item-main\")]//p[@class=\"company-name\"]/a'))\n",
    "\n",
    "# 作为xpath字典，键为我要抓的牛肉名称，值为xpath\n",
    "dict_xpaths={ \n",
    "    'text': {\n",
    "        'edu':      '//div[contains(@class,\"job-info\")]/p/span[@class=\"edu\"]',\n",
    "        '经验':      '//div[contains(@class,\"job-info\")]/p/span[@class=\"edu\"]/following-sibling::span',\n",
    "        '薪水':    '//div[contains(@class,\"job-info\")]/p/span[@class=\"text-warning\"]', \n",
    "        '时间':    '//div[contains(@class,\"job-info\")]/p/time/@title', \n",
    "        '职称':    '//div[contains(@class,\"job-info\")]/h3/a', \n",
    "        '公司地点': '//div[contains(@class,\"job-info\")]/p/a',\n",
    "        '公司名称': '//div[contains(@class,\"sojob-item-main\")]//p[@class=\"company-name\"]/a', \n",
    "    },\n",
    "    'text_content': {\n",
    "    },\n",
    "    'href': {\n",
    "        '链结':    '//div[contains(@class,\"job-info\")]/h3/a', \n",
    "        '公司URL': '//div[contains(@class,\"sojob-item-main\")]//p[@class=\"company-name\"]/a', \n",
    "    }\n",
    "}\n",
    "\n",
    "def get_e_text_content(_xpath_):\n",
    "    # 高级列表推导\n",
    "    暂存结果 = [e.xpath(_xpath_)[0].lxml.text_content() for e in 主要元素]\n",
    "    return(暂存结果)\n",
    "\n",
    "def get_e_text(_xpath_):\n",
    "    # 高级列表推导\n",
    "    暂存结果 = [\"\".join([x.strip() if type(x) is str else x.text.strip() for x in e.xpath(_xpath_)]) for e in 主要元素]\n",
    "    return(暂存结果)\n",
    "\n",
    "def get_e_href(_xpath_):\n",
    "    # 高级列表推导\n",
    "    暂存结果 = [list(e.xpath(_xpath_, first=True).absolute_links)[0] \\\n",
    "               if len(e.xpath(_xpath_, first=True).absolute_links) >= 1  \\\n",
    "               else \"\" for e in 主要元素]\n",
    "    return(暂存结果)\n",
    "\n",
    "# 只对主要元素下进行.xpath取值\n",
    "数据字典 = dict()\n",
    "\n",
    "数据字典 = {k:get_e_text_content(v) for k,v in dict_xpaths['text_content'].items()}\n",
    "数据字典.update({k:get_e_text(v) for k,v in dict_xpaths['text'].items()})\n",
    "数据字典.update({k:get_e_href(v) for k,v in dict_xpaths['href'].items()})\n",
    "\n",
    "[len(v) for k,v in 数据字典.items()]\n",
    "\n",
    "数据 = pd.DataFrame(数据字典)\n",
    "#数据.to_excel(\"20春_Web数据挖掘_week03_liepin.xlsx\", sheet_name=\"搜查结果\")\n",
    "数据 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### xpath解析翻页"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 单一页面\n",
    "url = \"https://www.liepin.com/zhaopin/?key=短视频运营\"\n",
    "session = HTMLSession()\n",
    "r = session.get( url )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<Element 'a' href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1'>, <Element 'a' href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=2'>, <Element 'a' href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=3'>, <Element 'a' href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=4'>, <Element 'a' href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1'>, <Element 'a' class=('last',) href='/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=9' title='末页'>]\n",
      "{'2': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1', '3': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=2', '4': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=3', '5': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=4', '下一页': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1', '': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=9'}\n"
     ]
    }
   ],
   "source": [
    "# xpath 解析翻页a/@href\n",
    "xpath_翻页a = '//div[@class=\"pagerbar\"]/a' # 有disabled, current等href是javascript\n",
    "xpath_翻页a = '//div[@class=\"pagerbar\"]/a[starts-with(@href,\"/zhaopin\")]'\n",
    "print (r.html.xpath(xpath_翻页a)) # 物件\n",
    "\n",
    "href_列表 = [x.xpath('//@href')[0] for x in r.html.xpath(xpath_翻页a)]\n",
    "#print (href_列表)\n",
    "\n",
    "文字_列表 = [x.text for x in r.html.xpath(xpath_翻页a)]\n",
    "#print (文字_列表)\n",
    "\n",
    "href_字典 = {x.text:x.xpath('//@href')[0]  for x in r.html.xpath(xpath_翻页a)}\n",
    "print (href_字典)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 构建参数模板"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>scheme</th>\n",
       "      <th>netloc</th>\n",
       "      <th>path</th>\n",
       "      <th>params</th>\n",
       "      <th>query</th>\n",
       "      <th>fragment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>/zhaopin/</td>\n",
       "      <td></td>\n",
       "      <td>compkind=&amp;dqs=&amp;pubTime=&amp;pageSize=40&amp;salary=&amp;co...</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  scheme netloc       path params  \\\n",
       "0                /zhaopin/          \n",
       "1                /zhaopin/          \n",
       "2                /zhaopin/          \n",
       "3                /zhaopin/          \n",
       "4                /zhaopin/          \n",
       "5                /zhaopin/          \n",
       "\n",
       "                                               query fragment  \n",
       "0  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           \n",
       "1  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           \n",
       "2  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           \n",
       "3  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           \n",
       "4  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           \n",
       "5  compkind=&dqs=&pubTime=&pageSize=40&salary=&co...           "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "scheme      1\n",
      "netloc      1\n",
      "path        1\n",
      "params      1\n",
      "query       5\n",
      "fragment    1\n",
      "dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>pageSize</th>\n",
       "      <th>sortFlag</th>\n",
       "      <th>key</th>\n",
       "      <th>siTag</th>\n",
       "      <th>d_sfrom</th>\n",
       "      <th>d_ckId</th>\n",
       "      <th>d_curPage</th>\n",
       "      <th>d_pageSize</th>\n",
       "      <th>d_headId</th>\n",
       "      <th>curPage</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>40</td>\n",
       "      <td>°radeFlag=0</td>\n",
       "      <td>短视频运营</td>\n",
       "      <td>icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw</td>\n",
       "      <td>search_unknown</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>0</td>\n",
       "      <td>40</td>\n",
       "      <td>375622397438f45e120a2d401e5740aa</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  pageSize     sortFlag    key                                          siTag  \\\n",
       "0       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "1       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "2       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "3       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "4       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "5       40  °radeFlag=0  短视频运营  icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw   \n",
       "\n",
       "          d_sfrom                            d_ckId d_curPage d_pageSize  \\\n",
       "0  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "1  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "2  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "3  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "4  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "5  search_unknown  375622397438f45e120a2d401e5740aa         0         40   \n",
       "\n",
       "                           d_headId curPage  \n",
       "0  375622397438f45e120a2d401e5740aa       1  \n",
       "1  375622397438f45e120a2d401e5740aa       2  \n",
       "2  375622397438f45e120a2d401e5740aa       3  \n",
       "3  375622397438f45e120a2d401e5740aa       4  \n",
       "4  375622397438f45e120a2d401e5740aa       1  \n",
       "5  375622397438f45e120a2d401e5740aa       9  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pageSize      1\n",
      "sortFlag      1\n",
      "key           1\n",
      "siTag         1\n",
      "d_sfrom       1\n",
      "d_ckId        1\n",
      "d_curPage     1\n",
      "d_pageSize    1\n",
      "d_headId      1\n",
      "curPage       5\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 建构参数模板：找到关键参数及参数结构\n",
    "from urllib.parse import urlparse, parse_qs\n",
    "import pandas as pd\n",
    "from IPython.display import display, HTML\n",
    "\n",
    "# 总体目标：输入 href_列表, 建构出参数字典\n",
    "\n",
    "# urlparse 解析后丢入数据框\n",
    "df = pd.DataFrame([ urlparse(x) for x in href_列表])\n",
    "df_qs = pd.DataFrame([{k:v[0] for k,v in parse_qs(x).items()} for x in df['query'] ])\n",
    "\n",
    "display(df)\n",
    "print(df.nunique())\n",
    "display(df_qs)\n",
    "print(df_qs.nunique())\n",
    "\n",
    "df_qs.curPage\n",
    "df_qs = df_qs.assign (curPage_int=df_qs.curPage.astype(int)) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 建构参数模板：curPage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'pageSize': ['40'], 'sortFlag': ['°radeFlag=0'], 'key': ['短视频运营'], 'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'], 'd_sfrom': ['search_unknown'], 'd_ckId': ['375622397438f45e120a2d401e5740aa'], 'd_curPage': ['0'], 'd_pageSize': ['40'], 'd_headId': ['375622397438f45e120a2d401e5740aa'], 'curPage': ['1']}\n",
      "{'2': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1', '3': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=2', '4': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=3', '5': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=4', '下一页': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=1', '': '/zhaopin/?compkind=&dqs=&pubTime=&pageSize=40&salary=&compTag=&sortFlag=°radeFlag=0&compIds=&subIndustry=&jobKind=&industries=&compscale=&key=%E7%9F%AD%E8%A7%86%E9%A2%91%E8%BF%90%E8%90%A5&siTag=icgOLfoBEcDFRuwEbVrpTQ%7EfA9rXquZc5IkJpXC-Ycixw&d_sfrom=search_unknown&d_ckId=375622397438f45e120a2d401e5740aa&d_curPage=0&d_pageSize=40&d_headId=375622397438f45e120a2d401e5740aa&curPage=9'}\n"
     ]
    }
   ],
   "source": [
    "# 建构参数模板：找到关键参数及参数结构\n",
    "\n",
    "def parse_url_qs_for_curPage (url):\n",
    "    six_parts = urlparse(url) \n",
    "    out = parse_qs(six_parts.query)\n",
    "    return (out)\n",
    "\n",
    "# 取一例做模板\n",
    "参数模板 = parse_url_qs_for_curPage(href_列表[0])\n",
    "print (参数模板)\n",
    "\n",
    "print (href_字典)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "9\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{0: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [0],\n",
       "  'keyword': ['短视频运营']},\n",
       " 1: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [1],\n",
       "  'keyword': ['短视频运营']},\n",
       " 2: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [2],\n",
       "  'keyword': ['短视频运营']},\n",
       " 3: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [3],\n",
       "  'keyword': ['短视频运营']},\n",
       " 4: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [4],\n",
       "  'keyword': ['短视频运营']},\n",
       " 5: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [5],\n",
       "  'keyword': ['短视频运营']},\n",
       " 6: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [6],\n",
       "  'keyword': ['短视频运营']},\n",
       " 7: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [7],\n",
       "  'keyword': ['短视频运营']},\n",
       " 8: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [8],\n",
       "  'keyword': ['短视频运营']},\n",
       " 9: {'pageSize': ['40'],\n",
       "  'sortFlag': ['°radeFlag=0'],\n",
       "  'key': ['短视频运营'],\n",
       "  'siTag': ['icgOLfoBEcDFRuwEbVrpTQ~fA9rXquZc5IkJpXC-Ycixw'],\n",
       "  'd_sfrom': ['search_unknown'],\n",
       "  'd_ckId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'd_curPage': ['0'],\n",
       "  'd_pageSize': ['40'],\n",
       "  'd_headId': ['375622397438f45e120a2d401e5740aa'],\n",
       "  'curPage': [9],\n",
       "  'keyword': ['短视频运营']}}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 建构参数模板生成器：keyword curPage\n",
    "def 参数模板生成(keyword, curPage):\n",
    "    参数 = 参数模板.copy()\n",
    "    参数['curPage'] = curPage\n",
    "    参数['keyword'] = keyword\n",
    "    return (参数)\n",
    "\n",
    "参数_keyword_短视频运营_curPage = { \n",
    "    i:参数模板生成(curPage = [i], \\\n",
    "                  keyword = ['短视频运营']) \\\n",
    "    for i,v in href_字典.items()\\\n",
    "    }\n",
    "\n",
    "# print(参数_keyword_用户体验_curPage) # 只生成本页有的额外翻页URL, 并没有推估到&curPage=9,也没有这页\n",
    "\n",
    "print (df_qs.curPage_int.min()) # 最小值只有1\n",
    "print (df_qs.curPage_int.max()) # 最大值只有9\n",
    "\n",
    "# 应该是 0 (本页)....9(最大值)\n",
    "\n",
    "参数_keyword_短视频运营_curPage = { \n",
    "    i:参数模板生成(curPage = [i], \\\n",
    "                  keyword = ['短视频运营']) \\\n",
    "    for i in range(0,df_qs.curPage_int.max()+1)\\\n",
    "    }\n",
    "参数_keyword_短视频运营_curPage"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 爬亦有道"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# requests_liepin\n",
    "session = HTMLSession()\n",
    "\n",
    "def requests_liepin( url, params):\n",
    "    r = session.get( url , params = payload)\n",
    "\n",
    "    # 先取特定元素, 精准打击其子后辈\n",
    "    主要元素 = r.html.xpath( '//ul[@class=\"sojob-list\"]/li')\n",
    "\n",
    "    # 作为xpath字典，键为我要抓的牛肉名称，值为xpath\n",
    "    dict_xpaths={ \n",
    "        'text': {\n",
    "            'edu':      '//div[contains(@class,\"job-info\")]/p/span[@class=\"edu\"]',\n",
    "            '经验':      '//div[contains(@class,\"job-info\")]/p/span[@class=\"edu\"]/following-sibling::span',\n",
    "            '薪水':    '//div[contains(@class,\"job-info\")]/p/span[@class=\"text-warning\"]', \n",
    "            '时间':    '//div[contains(@class,\"job-info\")]/p/time/@title', \n",
    "            '职称':    '//div[contains(@class,\"job-info\")]/h3/a', \n",
    "            '公司地点': '//div[contains(@class,\"job-info\")]/p/a',\n",
    "            '公司名称': '//div[contains(@class,\"sojob-item-main\")]//p[@class=\"company-name\"]/a', \n",
    "        },\n",
    "        'text_content': {\n",
    "        },\n",
    "        'href': {\n",
    "            '链结':    '//div[contains(@class,\"job-info\")]/h3/a', \n",
    "            '公司URL': '//div[contains(@class,\"sojob-item-main\")]//p[@class=\"company-name\"]/a', \n",
    "        }\n",
    "    }\n",
    "\n",
    "    def get_e_text_content(_xpath_):\n",
    "        # 高级列表推导\n",
    "        暂存结果 = [e.xpath(_xpath_)[0].lxml.text_content() for e in 主要元素]\n",
    "        return(暂存结果)\n",
    "\n",
    "    def get_e_text(_xpath_):\n",
    "        # 高级列表推导\n",
    "        暂存结果 = [\"\".join([x.strip() if type(x) is str else x.text.strip() for x in e.xpath(_xpath_)]) for e in 主要元素]\n",
    "        return(暂存结果)\n",
    "\n",
    "    def get_e_href(_xpath_):\n",
    "        # 高级列表推导\n",
    "        暂存结果 = [list(e.xpath(_xpath_, first=True).absolute_links)[0] \\\n",
    "                   if len(e.xpath(_xpath_, first=True).absolute_links) >= 1  \\\n",
    "                   else \"\" for e in 主要元素]\n",
    "        return(暂存结果)\n",
    "\n",
    "    # 只对主要元素下进行.xpath取值\n",
    "    数据字典 = dict()\n",
    "\n",
    "    数据字典 = {k:get_e_text_content(v) for k,v in dict_xpaths['text_content'].items()}\n",
    "    数据字典.update({k:get_e_text(v) for k,v in dict_xpaths['text'].items()})\n",
    "    数据字典.update({k:get_e_href(v) for k,v in dict_xpaths['href'].items()})\n",
    "\n",
    "    数据 = pd.DataFrame(数据字典)\n",
    "    #数据.to_excel(\"20春_Web数据挖掘_week03_liepin.xlsx\", sheet_name=\"搜查结果\")\n",
    "    return (数据)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 56.8 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "url = \"https://www.liepin.com/zhaopin/\"\n",
    "\n",
    "list_df = list()\n",
    "for k,v in 参数_keyword_短视频运营_curPage.items():\n",
    "    payload = v\n",
    "    df = requests_liepin( url, params = payload)\n",
    "    time.sleep(3+4*random())  #放慢脚步 3-7秒, 平均约5秒\n",
    "    df = df.assign (curPage = k)  # 区分  curPage\n",
    "    list_df.append(df)\n",
    "\n",
    "df_all = pd.concat(list_df).reset_index()\n",
    "df_all.index.name = '序'\n",
    "\n",
    "# 上周C-4   输出\n",
    "df_all.to_excel(\"20春_Web数据挖掘_final_liepin_翻页.xlsx\",\\\n",
    "                sheet_name=\"短视频运营\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "短视频运营 10\n",
      "短视频编导 10\n",
      "Wall time: 1min 59s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "# B-3 多个页面+多个关键词\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "url = \"https://www.liepin.com/zhaopin/\"\n",
    "xpath_翻页a = '//div[@class=\"pagerbar\"]/a[starts-with(@href,\"/zhaopin\")]'\n",
    "\n",
    "keywords = ['短视频运营','短视频编导']\n",
    "list_df = list()\n",
    "\n",
    "## 第一页试探有多长的页面\n",
    "for key in keywords:\n",
    "    payload = 参数模板生成(keyword=[key], curPage=['0'])\n",
    "    df = requests_liepin( url, params = payload)\n",
    "    href_列表 = [x.xpath('//@href')[0] for x in r.html.xpath(xpath_翻页a)]\n",
    "    df = pd.DataFrame([ urlparse(x) for x in href_列表])\n",
    "    df_qs = pd.DataFrame([{k:v[0] for k,v in parse_qs(x).items()} for x in df['query'] ])\n",
    "    df_qs = df_qs.assign (curPage_int=df_qs.curPage.astype(int)) # 变成整数\n",
    "    长度 = df_qs.curPage_int.max()+1\n",
    "    参数_keyword_X_curPage = { \n",
    "        i:参数模板生成(curPage = [i], \\\n",
    "                      keyword = [key]) \\\n",
    "        for i in range(0,长度)\\\n",
    "        }\n",
    "    #print (参数_keyword_X_curPage)\n",
    "    print (key,长度)\n",
    "    \n",
    "    for k,v in 参数_keyword_X_curPage.items():\n",
    "        payload = v\n",
    "        df = requests_liepin( url, params = payload)\n",
    "        time.sleep(3+4*random())  #放慢脚步 3-7秒, 平均约5秒\n",
    "        df = df.assign (keyword = key)  # 区分  keyword    \n",
    "        df = df.assign (curPage = k)  # 区分  curPage    \n",
    "        list_df.append(df)\n",
    "        \n",
    "df_all = pd.concat(list_df).reset_index()\n",
    "df_all.index.name = '序'\n",
    "\n",
    "df_all.to_excel(\"双关键词_Web数据挖掘_final_liepin_翻页.xlsx\",\\\n",
    "                sheet_name=\"_\".join(keywords))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "短视频运营 10\n",
      "广州 10\n",
      "深圳 10\n",
      "Wall time: 2min 42s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "# B-3 多个页面+多个关键词\n",
    "import time\n",
    "from random import random\n",
    "\n",
    "url = \"https://www.liepin.com/zhaopin/\"\n",
    "xpath_翻页a = '//div[@class=\"pagerbar\"]/a[starts-with(@href,\"/zhaopin\")]'\n",
    "\n",
    "keywords = ['短视频运营','广州','深圳']\n",
    "list_df = list()\n",
    "\n",
    "## 第一页试探有多长的页面\n",
    "for key in keywords:\n",
    "    payload = 参数模板生成(keyword=[key], curPage=['0'])\n",
    "    df = requests_liepin( url, params = payload)\n",
    "    href_列表 = [x.xpath('//@href')[0] for x in r.html.xpath(xpath_翻页a)]\n",
    "    df = pd.DataFrame([ urlparse(x) for x in href_列表])\n",
    "    df_qs = pd.DataFrame([{k:v[0] for k,v in parse_qs(x).items()} for x in df['query'] ])\n",
    "    df_qs = df_qs.assign (curPage_int=df_qs.curPage.astype(int)) # 变成整数\n",
    "    长度 = df_qs.curPage_int.max()+1\n",
    "    参数_keyword_X_curPage = { \n",
    "        i:参数模板生成(curPage = [i], \\\n",
    "                      keyword = [key]) \\\n",
    "        for i in range(0,长度)\\\n",
    "        }\n",
    "    #print (参数_keyword_X_curPage)\n",
    "    print (key,长度)\n",
    "    \n",
    "    for k,v in 参数_keyword_X_curPage.items():\n",
    "        payload = v\n",
    "        df = requests_liepin( url, params = payload)\n",
    "        time.sleep(3+4*random())  #放慢脚步 3-7秒, 平均约5秒\n",
    "        df = df.assign (keyword = key)  # 区分  keyword    \n",
    "        df = df.assign (curPage = k)  # 区分  curPage    \n",
    "        list_df.append(df)\n",
    "        \n",
    "df_all = pd.concat(list_df).reset_index()\n",
    "df_all.index.name = '序'\n",
    "\n",
    "df_all.to_excel(\"职位和城市_Web数据挖掘_final_liepin_翻页.xlsx\",\\\n",
    "                sheet_name=\"_\".join(keywords))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
